package com.ecube.maintenance.components.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.TextView;

import com.ecube.maintenance.R;

/**
 * Created by wcx on 14-9-18.
 */

/**
 * 不可取消的ProgressDialog
 */
public class CustomProgressDialog extends Dialog {
    private static CustomProgressDialog customProgressDialog = null;
    private Context context = null;

    public CustomProgressDialog(Context context) {
        super(context);
        this.context = context;
    }

    public CustomProgressDialog(Context context, int theme) {
        super(context, theme);
    }

    public static CustomProgressDialog createDialog(Context context) {
        customProgressDialog = new CustomProgressDialog(context, R.style.CustomProgressDialog);
        customProgressDialog.setContentView(R.layout.dialog_progress_custom);
        customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;
        customProgressDialog.setCancelable(false);
        return customProgressDialog;
    }

    public void onWindowFocusChanged(boolean hasFocus) {

        if (customProgressDialog == null) {
            return;
        }

        ImageView imageView = (ImageView) customProgressDialog.findViewById(R.id.loading_img_view);
        AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();
        animationDrawable.start();
    }

    /**
     * [Summary]
     * setTitle 标题
     *
     * @param strTitle
     * @return
     */
    public CustomProgressDialog setTitle(String strTitle) {
        return customProgressDialog;
    }

    /**
     * [Summary]
     * setMessage 提示内容
     *
     * @param strMessage
     * @return instance
     */
    public CustomProgressDialog setMessage(String strMessage) {
        TextView msg = (TextView) customProgressDialog.findViewById(R.id.progress_loading_msg);
        if (msg != null) {
            msg.setText(strMessage);
        }
        return customProgressDialog;
    }
}
